# -*- coding: utf-8 -*-
from concurrent.futures import ThreadPoolExecutor
import time


def get():
    return "get"


def post():
    return "post"


def put():
    return "put"


def delete():
    return "delete"


values = [3, 4, 5, 6]

def cube(x):
    print(f'Cube of {x}:{x * x * x}')


if __name__ == '__main__':
    print("ok")
    result = []
    with ThreadPoolExecutor(max_workers=5) as exe:
        exe.submit(cube, 2)

        # Maps the method 'cube' with a list of values.
        result = exe.map(cube, values)

    for r in result:
        print(r)

    print(time.perf_counter())

"""
Python3 线程的停止方式
1.设置子线程为守护线程，（setdaemon=True），当主线程结束时，守护线程会自动结束
import threading

def run(args):
    while args:
        print(x)
t = threading.Thread(target=run,args=(1,),daemon=True)
t.start()
2.类里面直接标识位
import threading

class Test():
    def __init__(self):
        self._flag = False
    def run(self,x):
    while x:
        print(x,self._flag)
        if self._flag:
            break
            
    def terminate(self):
        self._flag = True

if __name__ == '__main__':
    test = Test()
    t = threading.Thread(target=test.run,args=(1,))
    t.start()
    p = 10
    while p:
        print(threading.activeCount())
        p = p -1
        
    test.terminate()
    t.join
---------------------------------------------------------------------
import threading
import time

class Job(threading.Thread):
    def _init__(self, *args,**kwargs):
        super(Job,self).__init(*args,**kwargs)
        self._flag = threading.Event() # 用于线程暂停
        self._flag.set()  # set True
        self._running = Threading.Event() # 用于停止线程的标识
        self._running.set()  # 将running设置为True
    
    def  run(self):
        while self._running.isSet():
            self._flag.wait()
            time.sleep(1)
            
    def pause(self):
        self._flag.clear()  # 阻塞线程
        
    def resume(self):
        self._flag.set()  # 设置为True，让线程执行
    
    def stop(self):
        self._flag.set() # 将线程从暂停状态恢复
        self._running.clear()   # 设置为False
"""
